<?php

namespace App\Http\Controllers\Admin\Crm;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Crm\ArticleCategory;

class CategoryController extends Controller
{
    function __construct()
    {
        view()->share([
            '_categories'=>'am-active',
            '_crm'=>'am-in',
            'categories' => ArticleCategory::all_category(),
            'cates' => ArticleCategory::cates(),
        ]);
    }

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
//        $categories = ArticleCategory::Sorted()->where('parent_id',0)->get();
//        foreach ($categories as &$category){
//            $category['children'] = ArticleCategory::where("parent_id",$category['id'])->get();
//        }
//        return $cates;

        return view('admin.crm.category.index');
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create(ArticleCategory $category)
    {

        return view('admin.crm.category.create',compact('category'));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
//        return $request->all();
        ArticleCategory::create($request->all());
        return redirect(route('crm.category.index'))->with('success','新增成功');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {

    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit(ArticleCategory $category)
    {
        return view('admin.crm.category.edit',compact('category'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
